const componentMapping = {
  form: 'AForm',
  formItem: 'AFormItem',
  input: 'AInput',
  number: 'AInputNumber',
  textarea: 'ATextarea',
  row: 'ARow',
  col: 'ACol',
  button: 'AButton',
  select: 'ASelect',
  option: 'AOption',
  selectV2: 'ASelect',
  switch: 'ASwitch',
  time: 'ATimePicker',
  timeSelect: 'ATimePicker',
  date: 'ADatePicker',
  year: 'AYearPicker',
  month: 'AMonthPicker',
  week: 'AWeekPicker',
  dateTime: 'ADatePicker',
  dateRange: 'ARangePicker',
  weekRange: 'ARangePicker',
  monthRange: 'ARangePicker',
  yearRange: 'ARangePicker',
  quarterRange: 'ARangePicker',
  dateTimeRange: 'ARangePicker',
  radioGroup: 'ARadioGroup',
  radio: 'ARadio',
  checkboxGroup: 'ACheckboxGroup',
  checkbox: 'ACheckbox',
  cascader: 'ACascader',
  rate: 'ARate',
  slider: 'ASlider',
  transfer: 'ATransfer',
  upload: 'AUpload',
  avatar: 'AAvatar',
  badge: 'ABadge',
  container: 'ALayout',
  header: 'ALayoutHeader',
  main: 'ALayoutContent',
  footer: 'ALayoutFooter',
  aside: 'ALayoutSider',
  card: 'ACard',
  carousel: 'ACarousel',
  carouselItem: 'ACarouselItem',
  collapse: 'ACollapse',
  collapseItem: 'ACollapseItem',
  descriptions: 'ADescriptions',
  descriptionsItem: 'ADescriptionsItem',
  empty: 'AEmpty',
  image: 'AImage',
  progress: 'AProgress',
  result: 'AResult',
  skeleton: 'ASkeleton',
  skeletonLine: 'ASkeletonLine',
  skeletonItem: 'ASkeletonItem',
  table: 'ATable',
  tableV2: 'ATable',
  tag: 'ATag',
  timeLine: 'ATimeline',
  timeLineItem: 'ATimelineItem',
  tree: 'ATree',
  treeV2: 'ATree',
  treeSelect: 'ATreeSelect',
  divider: 'ADivider',
  affix: 'AAffix',
  backTop: 'ABackTop',
  breadcrumb: 'ABreadcrumb',
  breadcrumbItem: 'ABreadcrumbItem',
  dropdown: 'ADropdown',
  dropdownMenu: 'ADsubmenu',
  dropdownItem: 'ADoption',
  menu: 'AMenu',
  menuItem: 'AMenuItem',
  subMenu: 'ASubMenu',
  icon: 'AIcon',
  pageHeader: 'APageHeader',
  steps: 'ASteps',
  step: 'AStep',
  tabs: 'ATabs',
  tabPane: 'ATabPane',
  alert: 'AAlert',
  dialog: 'AModal',
  drawer: 'ADrawer',
  popConfirm: 'APopConfirm',
  popover: 'APopover',
  tooltip: 'ATooltip',
};

const emitMapping = {
  'update:modelValue': [
    'input',
    'textarea',
    'select',
    'switch',
    'number',
    'selectV2',
    'time',
    'timeSelect',
    'radioGroup',
    'radio',
    'checkboxGroup',
    'checkbox',
    'cascader',
    'rate',
    'slider',
    'transfer',
    'color',
    'range',
    'treeSelect',
    'date',
    'year',
    'month',
    'week',
    'dateTime',
    'dateRange',
    'weekRange',
    'monthRange',
    'yearRange',
    'dateTimeRange',
  ],
};

const placeholderMapping = {
  input: (label: string) => '请输入' + label,
  checkboxGroup: (label: string) => '请选择' + label,
  checkbox: (label: string) => '请选择' + label,
  radioGroup: (label: string) => '请选择' + label,
  radio: (label: string) => '请选择' + label,
  textarea: (label: string) => '请输入' + label,
  search: (label: string) => '请选择' + label,
  number: (label: string) => '请输入' + label,
  select: (label: string) => '请选择' + label,
  selectV2: (label: string) => '请选择' + label,
  date: (label: string) => '请选择' + label,
  dateTime: (label: string) => '请选择' + label,
  time: (label: string) => '请选择' + label,
  timeSelect: (label: string) => '请选择' + label,
  month: (label: string) => '请选择' + label,
  cascader: (label: string) => '请选择' + label,
  treeSelect: (label: string) => '请选择' + label,
  dateRange: () => ['开始时间', '结束时间'],
  weekRange: () => ['开始时间', '结束时间'],
  monthRange: () => ['开始时间', '结束时间'],
  yearRange: () => ['开始时间', '结束时间'],
  dateTimeRange: () => ['开始时间', '结束时间'],
};

const modelMapping = {
  input: 'modelValue',
  switch: 'modelValue',
  select: 'modelValue',
  number: 'modelValue',
  selectV2: 'modelValue',
  time: 'modelValue',
  timeSelect: 'modelValue',
  radioGroup: 'modelValue',
  radio: 'modelValue',
  checkboxGroup: 'modelValue',
  checkbox: 'modelValue',
  modelValue: 'modelValue',
  range: 'modelValue',
  rate: 'modelValue',
  slider: 'modelValue',
  transfer: 'modelValue',
  color: 'modelValue',
  treeSelect: 'modelValue',
  date: 'modelValue',
  year: 'modelValue',
  month: 'modelValue',
  week: 'modelValue',
  dateTime: 'modelValue',
  dateRange: 'modelValue',
  weekRange: 'modelValue',
  monthRange: 'modelValue',
  yearRange: 'modelValue',
  dateTimeRange: 'modelValue',
};

const defaultValueMapping = {};

const defaultRequiredRuleMapping = {
  '*'(config: { [key: string]: any }, message: string | string[]) {
    if (config.required) {
      return [
        {
          required: true,
          message: Array.isArray(message) ? message.join('-') : message,
          trigger: 'change',
        },
      ];
    }
    return [];
  },
};

export default {
  componentMapping,
  emitMapping,
  placeholderMapping,
  modelMapping,
  defaultValueMapping,
  defaultRequiredRuleMapping,
  formMapping: {
    prop: 'field',
    linkPath: '___',
  },
  interception: {
    validate(form: any, callback?: (isValid: boolean) => void) {
      return form.validate(callback);
    },
  },
};
